﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using BookTransactionControllers.Services_Impl;
using System.Data;

public partial class Views_SearchResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String searchBy = Request.QueryString["SearchBy"].ToString();
        String Key = Request.QueryString["Key"].ToString();
        SqlCommand command = new SqlCommand();
        if (searchBy.Equals("Tit"))
        {
            command.CommandText = "Select Book.[Image], Book.Title, Category.CategoryName, Book.Author, Book.PublicationYear, Book.PurposeOfSelling From Book,Category Where Book.CategoryID = Category.ID and [Title] like '%"+Key+"%'";
        }
        else
        {
            if (searchBy.Equals("Au"))
            {
                command.CommandText = "Select Book.[Image], Book.Title, Category.CategoryName, Book.Author, Book.PublicationYear, Book.PurposeOfSelling From Book,Category Where Book.CategoryID = Category.ID and [Author] like '%" + Key + "%'";
            }
        }
        BookManagerImpl bookMngImpl = new BookManagerImpl();
        DataTable tblSearchBook = bookMngImpl.SelectTable(command,"Search Book");
        if (tblSearchBook.Rows.Count == 0)
        {
            lbMessage.Text = "No Data.:D";
        }
        else
        {
            rptSearchBook.DataSource = tblSearchBook;
            rptSearchBook.DataBind();
        }
    }
}